var t = Object.assign || function(t) {
    for (var e = 1; e < arguments.length; e++) {
        var n = arguments[e];
        for (var a in n) Object.prototype.hasOwnProperty.call(n, a) && (t[a] = n[a]);
    }
    return t;
}, e = getApp(), n = wx.createCanvasContext("myCanvas");

Page({
    data: {
        value: "你昨天晚上又没回我信息，我却看见你的游戏在线，在我再一次孜孜不倦的骚扰你的情况下,你终于跟我说了一句最长的话 “你他妈是不是有病” 我又陷入了沉思，这一定有什么含义,我想了很久你竟然提到了我的妈妈，原来你已经想得",
        time: "2020年3月26日 星期四",
        name: "斯文的鸡蛋",
        avatar: "/img/1.jpg"
    },
    // GetApi: function() {
    //     var t = this;
    //     wx.request({
    //         url: "https://api.oddfar.com/yl/q.php?c=1006&encode=text",
    //         method: "get",
    //         success: function(e) {
    //             console.log(e)
    //             var n = e.data.replace(/<br>/g, "\n");
    //             console.log(n), t.setData({
    //                 content: n
    //             });
    //         }
    //     });
    // },
    onLoad: function() {
        var n = this, a = e.globalData.result;
        wx.showLoading({
            title: "图片生成中..."
        }), this.setData(t({}, a), function() {
            return setTimeout(function() {
                return n.createCard();
            }, 300);
        });
    },
    onReady: function() {},
    onShow: function() {},
    drawText: function(t, e, n, a, o, i) {
        for (var s = 1, l = 0, r = 0, c = 0; c < e.length; c++) (l += t.measureText(e[c]).width) > i && (t.fillText(e.substring(r, c), a, n), 
        n += 22, l = 0, r = c, o += 30, s += 1), c == e.length - 1 && t.fillText(e.substring(r, c + 1), a, n);
        return s;
    },
    createCard: function() {
        var t = this, e = this.data, a = e.avatar, o = e.name, i = e.time, s = e.value;
        n.fillStyle = "#dE685E", n.fillRect(0, 0, 150, 250), n.setTextAlign("center"), n.font = "normal bold 18px  黑体", 
        n.fillStyle = "#fff", this.drawText(n, "舔狗日记", 45, 77, 60, 130), n.font = "normal bold 14px  黑体", 
        this.drawText(n, o, 205, 77, 60, 130), n.setTextAlign("left"), n.font = "normal bold 12px  黑体", 
        n.setTextAlign("left"), n.font = "normal bold 22px  黑体", n.fillStyle = "#000";
        this.drawText(n, i, 30, 170, 60, 250);
        n.font = "normal 16px 黑体", this.drawText(n, s, 60, 170, 60, 250);
        var l = {
            x: 55,
            y: 55,
            r: 55
        };
        n.save(), n.beginPath(), n.arc(75, 120, l.r, 0, 2 * Math.PI, !1), n.clip(), n.drawImage(a, 20, 65, 110, 110), 
        n.draw(), setTimeout(function() {
            return t.getImg();
        }, 200);
    },
    getImg: function() {
        var t = this;
        wx.canvasToTempFilePath({
            canvasId: "myCanvas",
            success: function(e) {
                t.setData({
                    img: e.tempFilePath
                }), wx.hideLoading();
            }
        });
    },
    save: function() {
        var t = this;
        wx.getSetting({
            success: function(e) {
                e.authSetting["scope.writePhotosAlbum"] ? t.saveImg() : void 0 === e.authSetting["scope.writePhotosAlbum"] ? wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        t.saveImg();
                    },
                    fail: function() {
                        wx.showToast({
                            title: "您没有授权，无法保存到相册",
                            icon: "none"
                        });
                    }
                }) : wx.openSetting({
                    success: function(e) {
                        e.authSetting["scope.writePhotosAlbum"] ? t.saveImg() : wx.showToast({
                            title: "您没有授权，无法保存到相册",
                            icon: "none"
                        });
                    }
                });
            }
        });
    },
    saveImg: function() {
        wx.canvasToTempFilePath({
            canvasId: "myCanvas",
            success: function(t) {
                console.log(t.tempFilePath), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showModal({
                            title: "提示",
                            content: "保存成功",
                            showCancel: !1,
                            success: function(t) {}
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    openQZone: function() {
        var t = this.data, e = t.time, n = t.value, a = t.img;
        wx.openQzonePublish({
            text: e + " " + n,
            media: [ {
                type: "photo",
                path: a
            } ]
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: "做舔狗呢，最重要的是开心",
            path: "/pages/index/index",
            imageUrl: "/img/1.jpg"
        };
    }
});